home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Miscellaneous / Randy Thelen / ThreadedSort / Misc Stuff / MPW-specific / CPlusRuntime.cp
Encoding:
Text File  |  1994-06-26  |  1.4 KB  |  67 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CPlusRuntime.cp
  3.  
  4.     Contains:    Implementation of C++ Runtime methods so we can avoid
  5.                 linking the application with CPlusLib.o and StdCLib.o
  6.                 which contain lots of extra baggage. An important part
  7.                 of this file is to make “new” allocate objects using
  8.                 NewPtr() instead of malloc(), which has a nasty memory
  9.                 leak (some might call it a design decision) in MPW C.
  10.                 We could just define malloc() here, but that still keeps
  11.                 alot of strange, UNIX-esque routines around.
  12.  
  13.     Written by: Dave Falkenburg
  14.  
  15.     Copyright:    © 1993-94 by Dave Falkenburg, all rights reserved.
  16.  
  17.     Change History (most recent first):
  18.     
  19.  */
  20.  
  21. #include <Memory.h>
  22. #include <stddef.h>    //    for size_t
  23.  
  24. #include "Exceptions.h"
  25.  
  26. #ifdef    MPW
  27.  
  28. //    MPW C++ calls the following C function
  29. //    if a pure virtual method is called at runtime
  30. //
  31. //    We provide our own version here to avoid linking in
  32. //    the entire CPlusLib.o. It saves some space.
  33.  
  34. extern "C"
  35.     {
  36.     void __pure_virtual_called(void);
  37.     }
  38.  
  39. void
  40. __pure_virtual_called(void)
  41.     {
  42.     DebugStr((ConstStr255Param) "\ppure virtual called.");
  43.     ExitToShell();
  44.     }
  45.  
  46. #endif
  47.  
  48.  
  49. void * operator new (size_t objectSize);
  50. void operator delete (void *objectToDelete);
  51.  
  52.  
  53. void *
  54. operator new (size_t objectSize)
  55.     {
  56.     void *newObject = NewPtr(objectSize);
  57.     return(newObject);
  58.     }
  59.  
  60.  
  61. void
  62. operator delete (void *objectToDelete)
  63.     {
  64.     if (objectToDelete)
  65.         DisposePtr((Ptr) objectToDelete);
  66.     }
  67.